<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var obj1 = {
            a: 1,
            b: {
                c: 2
            },
            d: 3
        }
        obj1.a = 10;
        obj1.b.c = 20;
        obj1.d = 30;

        //深拷贝
        var obj2 = JSON.parse(JSON.stringify(obj1))

        console.log(obj2);

        //浅拷贝
        // var obj2 = Object.assign({}, obj1)
    </script>
</body>

</html>